package com.ycsj.goldmedalnewconcept.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.ycsj.goldmedalnewconcept.utils.CleanUtils;
import com.ycsj.goldmedalnewconcept.utils.DataCleanManager;
import com.ycsj.goldmedalnewconcept.R;

//设置
public class SettingActivity extends Activity implements OnClickListener {
	private ImageView iv_back;
	private RelativeLayout rl_msgsetting;
	private RelativeLayout rl_deletecache;
	private Intent intent;
	private AlertDialog alertDialog;
	private Window window;
	private int dialogWidth = 550;
	private int dialogHeight = 260;
	private WindowManager.LayoutParams lp;
	private Button okClean;
	protected Button cancel;
	private Display mDisplay;
	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		getPhoneWindow();
		initView();
		setOnListener();
		initData();
		
	}
	private void getPhoneWindow() {
		mDisplay = getWindowManager().getDefaultDisplay();

		int W = mDisplay.getWidth();
		int H = mDisplay.getHeight();

		dialogWidth = W*2/3;
		dialogHeight = dialogWidth/2;
		
	}
	private void initView() {
		// TODO Auto-generated method stub
		iv_back = (ImageView) findViewById(R.id.iv_back);
		rl_msgsetting = (RelativeLayout) findViewById(R.id.rl_msgsetting);
		rl_deletecache = (RelativeLayout) findViewById(R.id.rl_deletecache);
	}

	private void initData() {
		// TODO Auto-generated method stub

	}

	private void setOnListener() {
		// TODO Auto-generated method stub
		iv_back.setOnClickListener(this);
		rl_msgsetting.setOnClickListener(this);
		rl_deletecache.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.iv_back:
			finish();
			break;
		case R.id.rl_msgsetting:	//消息提醒设置
			intent = new Intent(this,MsgSettingActivity.class);
			startActivity(intent);
			break;
		case R.id.rl_deletecache:	//清除缓存
			cleanDialog();  	
			break;
		}
	}
	
	//清除缓存
	private void cleanDialog() {
		alertDialog = new AlertDialog.Builder(this).create();
		alertDialog.show();
		window = alertDialog.getWindow();
		lp = window.getAttributes();
		lp.x = 0;
//		lp.y = -110;
		window.setContentView(R.layout.dialog_clean);
		alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable());
		window.setLayout(dialogWidth, dialogHeight);
		cancel = (Button) alertDialog.getWindow().findViewById(
				R.id.dialog_cancel);
		okClean = (Button) alertDialog.getWindow().findViewById(R.id.dialog_clean);
		
		cancel.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				alertDialog.dismiss();
			}
		});
		
		okClean.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
//				CleanUtils.cleanInternalCache(getBaseContext());
//				CleanUtils.cleanInternalFiles(getBaseContext());
//				CleanUtils.cleanInternalDbs(getBaseContext());
				Toast.makeText(getBaseContext(), "成功清除本地缓存", 0).show();
				alertDialog.dismiss();
				
				DataCleanManager.clearAllCache(SettingActivity.this);
				
				
			}
		});
		
		
	}

}









